import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { VersioningType } from '@nestjs/common';
//导入express-session
import session from 'express-session';
//全局响应拦截器
import { ResponseInterceptor } from './response/response.interceptor';
//全局异常过滤器
import { ErrorfilterFilter } from './errorfilter/errorfilter.filter';
//全局token的守卫
import { AuthGuard } from './auth/auth.guard';
import { JwtService } from '@nestjs/jwt'

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  //开启版本控制
  app.enableVersioning({
    type:VersioningType.URI
  })
  //设置全局的路由前缀api
  app.setGlobalPrefix('api')
  //设置express-session
  app.use(session({
    secret:'93d39a31-8d49-4a03-9c56-4e37b469a324',
    name:'zhouck_sid',
    rolling:true,
    cookie:{
      maxAge:null
    }
  }))
  //引入全局响应拦截器
  // app.useGlobalInterceptors(new ResponseInterceptor())
  //引入全局错误过滤器
  // app.useGlobalFilters(new ErrorfilterFilter())

  //注册全局路由守卫(查看token)
  // app.useGlobalGuards(new AuthGuard(new JwtService()))
  await app.listen(3000);
}
bootstrap();
